package argo.hot100;

import java.util.*;

public class GroupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {

        List<List<String>> res = new ArrayList<>();
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            List<String> subres = map.getOrDefault(Arrays.toString(chars), new ArrayList<>());
            subres.add(str);
            map.put(Arrays.toString(chars), subres);
        }

        for (List<String> value : map.values()) {
            res.add(value);
        }

        return res;

    }

    public static void main(String[] args) {
        System.out.println(new GroupAnagrams().groupAnagrams(new String[]{"eat", "tea", "tan", "ate", "nat", "bat"}));
    }
}
